﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LicenserProduction
{
    public partial class CustomerData : UserControl
    {
        public CustomerData(LicenserInformation ds, int custId)
        {
            InitializeComponent();
            licenserInformation = ds;
            customerInfoBindingSource.DataSource = licenserInformation;
            if (custId != Int32.MaxValue)
            {
                customerInfoBindingSource.Filter = "CustomerId = " + custId;
                customerInfoBindingSource.AllowNew = false;
            }
        }

        private void customerInfoBindingSource_BindingComplete(object sender, BindingCompleteEventArgs e)
        {
            if (e.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate)
            {
                if (e.BindingCompleteState == BindingCompleteState.Success)
                {
                    if (OnDataUpdate != null)
                    {
                        OnDataUpdate(this, new EventArgs());
                    }
                    btnSynchronize.Enabled = true;
                }
            }
        }

        private void btnSynchronize_Click(object sender, EventArgs e)
        {
            customerInfoBindingSource.EndEdit();
            if (OnSynchronize != null)
            {
                OnSynchronize(this, new EventArgs());
            }
        }

        public delegate void _OnSynchronize(object sender, EventArgs e);
        public delegate void _OnDataUpdate(object sender, EventArgs e);
        public event _OnSynchronize OnSynchronize;
        public event _OnDataUpdate OnDataUpdate;

    }
}
